 <?php
if ($this->session->userdata('logged_in') == 0) {
	redirect('/login');
}
?>

<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" href="<?php echo base_url('assets'); ?>/favicon.ico" type="image/x-icon" />

    <title><?php echo $title; ?></title>

    <link href="<?php echo base_url('assets/css/bootstrap.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/font-awesome/css/font-awesome.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/font-awesome/css/font-awesome.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/plugins/iCheck/custom.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/plugins/chosen/chosen.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/table.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/plugins/jQueryUI/jquery-ui-1.10.4.custom.min.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/plugins/jqGrid/ui.jqgrid.css'); ?>" rel="stylesheet">
    <!-- Gritter -->
    <link href="<?php echo base_url('assets/js/plugins/gritter/jquery.gritter.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/animate.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/style.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/mybutton.css'); ?>" rel="stylesheet">

    <link href="<?php echo base_url('assets/') ?>/css/plugins/summernote/summernote.css" rel="stylesheet">
    <link href="<?php echo base_url('assets/') ?>/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">

    <script src="<?php echo base_url('assets/js/jquery-2.1.1.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/bootstrap.min.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/metisMenu/jquery.metisMenu.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/slimscroll/jquery.slimscroll.min.js'); ?>"></script>

    <!-- Peity -->
    <script src="<?php echo base_url('assets/js/plugins/peity/jquery.peity.min.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/demo/peity-demo.js'); ?>"></script>

    <!-- Custom and plugin javascript -->
    <script src="<?php echo base_url('assets/js/inspinia.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/pace/pace.min.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/validate/jquery.validate.min.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/notification.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/notifyme.js'); ?>"></script>

    <!-- SUMMERNOTE -->
    <script src="<?php echo base_url('assets/') ?>/js/plugins/summernote/summernote.min.js"></script>

    <!-- Additional CSS Themes file - not required-->
    <link rel="stylesheet" href="<?php echo base_url('assets/EasyAutocomplete/easy-autocomplete.themes.css'); ?>">
    <!-- Sweet alert -->
    <script src="<?php echo base_url('assets/js/plugins/sweetalert/sweetalert.min.js'); ?>"></script>

    <!-- Bootstrap Filestyle -->
    <script src="<?php echo base_url('assets/bootstrap-filestyle/src/bootstrap-filestyle.min.js'); ?>"></script>
    <!-- Custom and plugin javascript -->
    <!-- <script src="<?php echo base_url('assets/js/inspinia.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/pace/pace.min.js'); ?>"></script> -->

</head>
<body style="background-color: ##FEFEFE;" onunload="javascript:confirm_unload()">
<div class="wrapper wrapper-content page-heading animated fadeInRight">
    <div class="row">
        <div class="col-lg-9">
          <div class="ibox-content">
            <form class="form-horizontal" id="email_form">
                <div class="form-group"><label class="col-sm-2 control-label">From:</label>
                    <div class="col-sm-10"><input name="email_from" type="text" class="form-control" value="Gfxgee@gee.com"></div>
                </div>
                <div class="form-group"><label class="col-sm-2 control-label">To:</label>
                    <div class="col-sm-10"><input name="email_to" type="text" class="form-control" value=""></div>
                </div>
                <div class="form-group"><label class="col-sm-2 control-label">Subject:</label>
                    <div class="col-sm-10"><input name="email_subj" type="text" class="form-control" value=""></div>
                </div>
                 <div class="form-group"><label class="col-sm-2 control-label">File Name:</label>
                    <div class="col-sm-10"><input name="email_filename" type="text" class="form-control" value=""></div>
                </div>
                <div class="form-group"><label class="col-sm-2 control-label">File Type:</label>
                   <div class="col-sm-10"><label class="checkbox-inline">
                    <input type="checkbox" name="email_topdf" value="pdf" checked> PDF (.pdf) </label> <label class="checkbox-inline">
                    <input type="checkbox" name="email_toexcel" value="excel" > EXCEL (.xls) </label>
                    <input style="border: none; width:0px" readonly type="text" name="email_error" value="">
                  </div>
                </div>
                 <div class="form-group"><label class="col-sm-2 control-label">Message:</label>
                    <div class="col-sm-10">
                      <div id="summernote"></div>
                    </div>
                </div>
                <div class="form-group"><label class="col-sm-2 control-label"></label>
                   <div class="col-sm-10">
                     <button type="button" class="btn btn-white btn-md m-t-n-xs pull-right" id="email_cancel">Close</button>
                     <button type="button" class="btn btn-success btn-md m-t-n-xs pull-right btn-margin-right" id="email_send">Send</button>
                  </div>
                </div>
            </form>
          </div>
        </div>
    </div><!-- END of class row-->
</div>
<script>
    sessionStorage.isClosed = '0';
    $(window).bind('beforeunload', function(e) {
    // Your code and validation
      if(sessionStorage.isClosed == '0'){
          if (confirm) {
              return "Are you sure?";
          }
      }
    });
      $(document).ready(function(){
        $(function(){
            $('#scroll').slimScroll({
              height: '250px'
            });
        });
      $('input[name=email_filename]').val('Collection_Details_Report ');
      $('.email_type').click(function(){
        sessionStorage.type = $(this).attr('id');
        console.log(sessionStorage.type);
      });
        // $('.footable').footable();
       $('#summernote').summernote({
          disableDragAndDrop: true,
          shortcuts: false,
          height: 200,
          placeholder: 'write here...',
          toolbar: [
            ['para', ['ul', 'ol', 'paragraph']]
          ]
        });

       $('#email_cancel').click(function(){
          if(sessionStorage.isClosed == '0'){
              if (confirm) {
                  return "Are you sure?";
              }
          }
       });

        $('#email_send').click(function(){
          if($("#email_form").valid() == true && fileType() == true){
            $.ajax({
              url: "<?php echo base_url($this->session->userdata('forajax')); ?>/send_mail",
              type: 'POST',
              dataType: 'json',
              data: $('#email_form').serialize()+'&'+$.param({ 'email_message': $('#summernote').code(), 'range1' : sessionStorage.range1, 'range2': sessionStorage.range2 }),
              success: function(data){
                if(data.msg == 'success'){
                  sessionStorage.isClosed = '1';
                }
                $('#email_send').html('Send');
                $('#email_send').removeAttr('disabled');
              },
              beforeSend: function(){
                $('#email_send').html('Sending..');
                $('#email_send').attr('disabled',true);
              }
            });
          }
        });

      function fileType(){
        if($("input[name=email_toexcel").prop('checked') == false && $("input[name=email_topdf").prop('checked') == false){
          var validator = $( "#email_form" ).validate();
          validator.showErrors({
            "email_error": "Please select atleast 1 filetype."
          });
          return false;
        }else{
          return true;
        }
      }

      $("#email_form").validate({
           rules: {
               email_to: {
                  required: true,
                  email: true
               },
               email_subj: {
                  required: true
               },
               email_from: {
                  required: true
               },
               email_filename: {
                required: true
               }
           }
        });
      });
</script>
</body>
</html>
